<template>
<section class="carActivate">
  <el-dialog
    v-dialogDrag
    :visible="popupsVisible"
    :title='titleName'
    width="70%"
    top="2rem"
    :append-to-body="true"
    :close-on-click-modal="false"
    @close="sendCode"
  >
    <dialogHeader slot="title" :title="titleName" :style-type="$store.state.app.dialogType" />
    <div class="filter-container filter-params">
      <!-- 表单组件 -->
      <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :custom-obj="comp.customObj"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :date-options-type="comp.dateOptionsType"
            :data-to-object="comp.dataToObj"
            @changeCode="getComponentCode"
          />
        </el-row>
    </div>

     <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          :fixed="true"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
  </el-dialog>
  </section>
</template>

<script>
import dialogHeader from '@/components/dialogHeader'
import { formMixins } from '@/components/mixins/formMixins'
import { orgApis } from '@/api/vesalesapi.js'
export default {
  components: {
    dialogHeader
  },
  mixins: [formMixins],
  props: {
    popupsVisible: {
      type: Boolean,
      default: false
    },
    dataForForm: {
      type: Object,
      default: () => {}
    }
  },
    data() {
    return {
      transferOrderDId:'',   //订单字表id
      updateControlIdOd:'',  //并发字段id
      titleName: '车主信息',

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          icon: 'iconfont icon-confirm',
          clickEvent: () => this.save(),
          text: '激活',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          icon: 'iconfont icon-cancel',
          clickEvent: () => this.sendCode('0'),
          text: this.$t('sys.button.cancel'),
          position: 'right'
        }
      ],

      tableComponents: [
        {
          compKey: 'compKey1',
          labelName: '客户姓名：',
          codeField: 'signatoryname',
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isRequire: true,
          isMul: false,
          isMust: true,
          span:9
        },
        {
          compKey: 'compKey2',
          labelName: '联系电话：',
          codeField: 'signatoryphone',
          validrule: { isPhone: true, maxlength: 11 },
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isRequire: true,
          isMul: false,
          isMust: true,
          span:8
        },
        {
          compKey: 'compKey3',
          isComponent: true,
          labelName: '身份证正面：',
          codeField: 'fileAId',
          component: () => import('@/components/upload/imgUpload'),
          isMust: true,
          span: 8,
          dataToObj:{
            fileUrl: '/mp/file/notice/upload.do'
          },
          sendCode: () => { },
          focusCode: () => { },
          changeCode: () => {},
        },
        {
          compKey: 'compKey4',
          isComponent: true,
          labelName: '身份证反面：',
          codeField: 'fileBId',
          component: () => import('@/components/upload/imgUpload'),
          isMust: true,
          span: 8,
          dataToObj:{
            fileUrl: '/mp/file/notice/upload.do'
          },
          sendCode: () => { },
          focusCode: () => { },
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        VIN:'',
        signatoryname:'',
        signatoryphone:'',
        fileAId:'',
        fileBId:''
      }
    }
  },
  mounted() {
    this.formField.VIN = this.dataForForm.VIN
    this.formField.signatoryname = this.dataForForm.custName
    this.formField.signatoryphone = this.dataForForm.custTel
  },
  methods: {
    // form表单组件每个元素所占栅格栏数每行24格
    spanNum() {
      return 24
    },
    // 激活
    save() {
      this.$requestAPI({
        apiUrl: orgApis.updateExhibitionCar.APIUrl,
        variables: { ...this.formField }
      }).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        this.$message({message: response.msg})
        this.sendCode('1')
      })
    },
  }
}
</script>
<style lang='scss' scoped>
  .promptSpan{
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
// .dialog-footer{
//   position: relative;
// }
// .dialog-footer .el-button{
//   position: absolute;
//   right:0
// }
</style>

